package org.example.pinda.log;

import org.example.pinda.aspect.SysLogAspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 日志自动配置
 * <p>
 * 启动条件：
 * <ul>
 *     <li> 存在web环境 </li>
 *     <li> 配置文件中pinda.log.enabled=true </li>
 *     <li> 配置文件中不存在：pinda.log.enabled 值 </li>
 * </ul>
 *
 * @author ryan fawcett
 */
@EnableAsync
@Configuration
@ConditionalOnWebApplication
@ConditionalOnProperty(value = "pinda.log.enabled", havingValue = "true", matchIfMissing = true)
public class LogAutoConfiguration {

    @Bean
    @ConditionalOnBean
    public SysLogAspect sysLogAspect() {
        return new SysLogAspect();
    }

}
